package service

import (
	"docker_go/internal/models/entity"
	"docker_go/internal/models/vo"
	"time"
)

func (s Service) GetAllStudents() (res []vo.Student) {
	students := s.dao.GetAllStudents()
	for _, v := range students {
		student := vo.Student{
			StuName:       v.StuName,
			FamilyAddress: v.FamilyAddress,
			BirthDay:      v.BirthDay.Format("2006年01月02日"),
		}
		res = append(res, student)
	}
	return
}

func (s Service) InsertStudent(stu vo.Student) {
	birth, _ := time.ParseInLocation("2006-01-02", stu.BirthDay, time.Local)
	s.dao.InsertStudent(entity.Student{
		StuName:       stu.StuName,
		FamilyAddress: stu.FamilyAddress,
		BirthDay:      birth,
	})
}
